define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xiservice/worker/index' + location.search,
                    add_url: 'xiservice/worker/add',
                    edit_url: 'xiservice/worker/edit',
                    del_url: 'xiservice/worker/del',
                    multi_url: 'xiservice/worker/multi',
                    import_url: 'xiservice/worker/import',
                    table: 'xiservice_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,     
                showExport: false,
                showToggle: false,
                showColumns: false,                
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('师傅编号'), operate: false},
                        {field: 'contact_name', title: __('师傅姓名'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'mobile', title: __('Mobile'), visible:false,operate: 'LIKE'},
                        {field: 'mobile_text', title: __('Mobile'), operate: false},
                        {field: 'service_num', title: __('Service_num'), operate: false},
                        {field: 'can_money', title: __('Can_money'), operate: false},
                        {field: 'freeze_money', title: __('Freeze_money'), operate: false},
                        {field: 'total_money', title: __('Total_money'), operate: false},
                        {field: 'idcard_front_image', title: __('Idcard_front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'idcard_back_image', title: __('Idcard_back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'extra_image', title: __('技能证书(企业:提供营业执照,从业人员提供岗位证书,药品的三证以及购买药品的发票.个人:提供岗位证书,药品的三证以及购买药品的发票)'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'desc', title: __('自我介绍'), operate: false},
                        {field: 'citytxt', title: __('当前城市'), operate: false},
                        {field: 'uptime', title: __('下次可修改城市时间'), operate: false},
                        {field: 'addr_detail', title: __('详细地址'), operate: false},
                        {field: 'pay_money', title: __('保证金'), operate: false},
                        {field: 'clothing_size', title: __('衣服尺码'), operate: false},
                        {field: 'pants_size', title: __('裤子尺码'), operate: false},
                        {field: 'hat_size', title: __('帽子'), operate: false},
                        {field: 'waistcoat_size', title: __('马甲尺码'), operate: false},
                        {field: 'pay_money', title: __('保证金'), operate: false},
                        {field: 'review', title: __('服务分'), operate: false},
                        {field: 'credit_score', title: __('信誉分'), operate: false},
                        {field: 'bond_status', title: __('保证金支付状态'), searchList: {"1":__('已支付'),"2":__('未支付')}, formatter: Table.api.formatter.status},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('收入明细'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    text: __('收入明细'),
                                    title: __('收入明细'),
                                    classname: 'btn btn-xs btn-warning  btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'xiservice/benfit/index?ids={id}'
                                }
                            ],
                            formatter: Table.api.formatter.buttons,
                            operate:false
                        },                           
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,  buttons: [
                            
                            {
                                name: 'addtabs',
                                text: __('扣除保证金'),
                                title: __('扣除保证金'),
                                classname: 'btn btn-xs btn-warning  btn-dialog',
                                // icon: 'fa fa-eye',
                                url: 'xiservice/worker/bond?ids={id}',
                            },
                            {
                                name: 'addtabs',
                                text: __('保证金充值'),
                                title: __('保证金充值'),
                                classname: 'btn btn-xs btn-warning  btn-dialog',
                                // icon: 'fa fa-eye',
                                url: 'xiservice/worker/bondadd?ids={id}',
                            },
                            {
                                name: 'addtabs',
                                text: __('扣除信誉分'),
                                title: __('扣除信誉分'),
                                classname: 'btn btn-xs btn-warning  btn-dialog',
                                // icon: 'fa fa-eye',
                                url: 'xiservice/worker/reviewone?ids={id}', 
                            }
                            // {
                            //     name: 'addtabs',
                            //     text: __('修改师傅服务城市'),
                            //     title: __('修改师傅服务城市'),
                            //     classname: 'btn btn-xs btn-warning  btn-dialog',
                            //     // icon: 'fa fa-eye',
                            //     url: 'xiservice/worker/upsfcs?ids={id}', 
                            // }
                        ],}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        audit: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xiservice/worker/audit' + location.search,
                    add_url: 'xiservice/worker/add',
                    edit_url: 'xiservice/worker/edit',
                    multi_url: 'xiservice/worker/multi',
                    import_url: 'xiservice/worker/import',
                    table: 'xiservice_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,     
                showExport: false,
                showToggle: false,
                showColumns: false,                
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('师傅编号'), operate: false},
                        {field: 'contact_name', title: __('Username'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'mobile', title: __('Mobile'), visible:false,operate: 'LIKE'},
                        {field: 'mobile_text', title: __('Mobile'), operate: false},
                        {field: 'idcard_front_image', title: __('Idcard_front_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'idcard_back_image', title: __('Idcard_back_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'extra_image', title: __('技能证书(企业:提供营业执照,从业人员提供岗位证书,药品的三证以及购买药品的发票.个人:提供岗位证书,药品的三证以及购买药品的发票)'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'desc', title: __('自我介绍'), operate: false},
                        {field: 'citytxt', title: __('当前城市'), operate: false},
                        {field: 'addr_detail', title: __('详细地址'), operate: false},
                        {field: 'pay_money', title: __('保证金'), operate: false},
                        {field: 'clothing_size', title: __('衣服尺码'), operate: false},
                        {field: 'pants_size', title: __('裤子尺码'), operate: false},
                        {field: 'hat_size', title: __('帽子'), operate: false},
                        {field: 'waistcoat_size', title: __('马甲尺码'), operate: false},
                        // {field: 'review', title: __('服务分'), operate: false},
                        {field: 'bond_status', title: __('保证金支付状态'), searchList: {"1":__('已支付'),"2":__('未支付')}, formatter: Table.api.formatter.status},
                        // 假设你的字段名为 'images'，并且它包含多张图片的URL地址，以逗号分隔
                 
                        {field: 'checkinfo', title: __('Checkinfo'), searchList: {"0":__('Checkinfo 0'),"1":__('Checkinfo 1'),"2":__('Checkinfo 2')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,                         
                          buttons: [
                                {
                                    name: 'addtabs',
                                    text: __('同意'),
                                    title: __('同意'),
                                    classname: 'btn btn-xs btn-warning  btn-ajax',
                                    icon: 'fa fa-check-square',
                                    url: 'xiservice/worker/agree?ids={id}',
                                    refresh:true,
                                    visible:function(row){
                                        if(row['checkinfo']==0 && (row['adminrole']==6 || row['adminrole']==1) && row['auth_status']==0){
                                            return true;
                                        }
                                         return false;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('同意'),
                                    title: __('同意'),
                                    classname: 'btn btn-xs btn-warning  btn-ajax',
                                    icon: 'fa fa-check-square',
                                    url: 'xiservice/worker/agree2?ids={id}',
                                    refresh:true,
                                    visible:function(row){
                                        if(row['checkinfo']==0 && (row['adminrole']==8 || row['adminrole']==1) && row['auth_status']==1){
                                            return true;
                                        }
                                         return false;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('拒绝'),
                                    title: __('拒绝'),
                                    classname: 'btn btn-xs btn-warning  btn-dialog',
                                    icon: 'fa fa-close',
                                    url: 'xiservice/worker/refuse?ids={id}',
                                    visible:function(row){
                                        if(row['checkinfo']==0){
                                            if(row['auth_status']==1 && row['adminrole']==6)
                                            {
                                                return false;
                                            }
                                            if(row['auth_status']==0 && row['adminrole']==8)
                                                {
                                                    return false;
                                                }
                                             return true;
                                         }
                                         return false;
                                    }
                                },
                                {
                                    name: 'addtabs',
                                    text: __('详情'),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-warning  btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'xiservice/worker/edit?ids={id}',
                                    
                                }
                            ],
                            formatter: Table.api.formatter.buttons,
                     }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },        
        add: function () {
            Controller.api.bindevent();
        },
        refuse: function () {
            Controller.api.bindevent();
        }, 
        
        upsfcs: function () {
            Controller.api.bindevent();
        }, 

        bond: function () {
            Controller.api.bindevent();
        },  
        bondadd: function () {
            Controller.api.bindevent();
        },  
        reviewone: function () {
            Controller.api.bindevent();
        },  
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
